package com.nikhu.fx.integration.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nikhu.fx.bom.Currency;
import com.nikhu.fx.integration.CurrencyService;

@Service
public class HibernateCurrencyServiceImpl implements CurrencyService {

	@Autowired
	private SessionFactory sessionFactory;

	public Currency get(String id) {
		Session session = sessionFactory.openSession();
		Currency currency = (Currency) session.get(Currency.class, id);
		session.close();
		return currency;
	}

	public List<Currency> findAll() {
		Session session = sessionFactory.openSession();
		Query query = session.createQuery("from Currency");
		List<Currency> currencies = (List<Currency>) query.list();
		session.close();
		return currencies;
	}
}
